@extends('admin/layout')

@section('title', $title)

@section('content')

<div class="content-wrapper" style="min-height: 923px;">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>
                用户管理
                <small>管理员列表</small>
            </h1>
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-dashboard"></i> 主页</a></li>
                <li><a href="#">用户管理</a></li>
                <li class="active">管理员列表</li>
            </ol>
        </section>

        <!-- Main content -->
        <section class="content">
            <div class="row">
                <div class="col-xs-12">
                    <div class="box">
                        <div class="box-header">
                            <h3 class="box-title">管理员列表</h3>
                        </div><!-- /.box-header -->
                        <div class="box-body">
                            <div id="example1_wrapper" class="dataTables_wrapper form-inline dt-bootstrap">
                                <form action="{{ url('/admin/user/list') }}">
                                {{ csrf_field() }}
                                <div class="row">
                                    <div class="col-md-9">
                                        <div class="dataTables_length" id="example1_length">
                                           
                                        </div>
                                    </div>
                                    
                            
                        
                                <div class="col-md-3">
                                    <div id="example1_filter" class="dataTables_filter">
                                        <label>搜索:
                                            <input class="form-control input-sm" placeholder="输入要搜索的邮箱地址" aria-controls="example1" type="text" name = 'keywords'>
                                            <button class="btn btn-primary">提交</button>
                                        </label>

                                    </div>
                                </div>

                            </div>
                            </form>
                            
                                @if(session('info'))
                                <div class="alert alert-info alert-dismissable col-md-4 col-md-offset-4">
                                <button class="close" type="button" data-dismiss="alert" aria-hidden="true">×</button>
                                <h4>
                                <i class="icon fa fa-info"></i>
                                    信息: {{session('info')}}
                                </h4>
                            
                            @endif
                            </div>
                            <div class="row">
                            <div class="col-sm-12">
                            <table id="example1" class="table table-bordered table-striped dataTable" role="grid" aria-describedby="example1_info">
                                <thead>
                                <tr role="row">
                                <th class="sorting_asc" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" style="width: 110.4px;" aria-sort="ascending" aria-label="Rendering engine: activate to sort column descending">ID</th><th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" style="width: 267.4px;" aria-label="Browser: activate to sort column ascending">邮箱</th>
                                <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" style="width: 144.4px;" aria-label="Platform(s): activate to sort column ascending">状态</th>
                                <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" style="width: 182.4px;" aria-label="Engine version: activate to sort column ascending">注册时间</th><th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" style="width: 235.2px;" aria-label="CSS grade: activate to sort column ascending">头像</th><th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" style="width: 235.2px;" aria-label="CSS grade: activate to sort column ascending">操作</th></tr>
                                </thead>
                                <tbody>
                                @foreach($data as $v)
                                <tr role="row" class="odd" >
                                    <td class="sorting_1" id='ids'>{{$v -> id}}</td>
                                    <td>{{$v -> email}}</td>
                                    <td >
                                    <span class='status'>
                                    @if($v -> status == 1)
                                        启用
                                    @elseif($v -> status == 0)
                                        禁用
                                    @endif
                                    </span>
                                    </td>
                                    <td>{{date('Y-m-d' ,$v -> regtime)}}</td>
                                    <td><img src="{{ url ('/uploads/portrait')}}/{{ $v -> pic }}" height='50'>
                                    </td>
                                    <td>
                                    <a href="{{ url('admin/user/deleteadmin') }}/{{$v -> id}}">删除</a>&nbsp;|&nbsp;<a href="{{ url('admin/user/admindetail') }}/{{ $v -> id }}">详情</a>|&nbsp;<a href="{{ url('admin/user/edit') }}/{{ $v -> id }}">编辑</a>
                                    </td>
                                </tr>
                                @endforeach

                                </tbody>

                            </table>
                            </div>
                            </div>
                            <div class="row">
                            <div class="col-sm-5">
                            </div>
                            <div class="col-sm-7">
                            <div class="dataTables_paginate paging_simple_numbers" id="example1_paginate">
                            {{ $data->appends($request)->render() }}
                            </div>
                            </div>
                            </div>
                            </div>
                        </div><!-- /.box-body -->
                    </div><!-- /.box -->
                </div><!-- /.col -->
            </div><!-- /.row -->
        </section><!-- /.content -->
    </div>

    <script type="text/javascript">

    window.onload = function()
    {
        $.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            }
        });

        //修改鼠标形状
        $('.mouse').css('cursor', 'pointer');
        $('.status').css('cursor', 'pointer');

        //单击更改用户状态
        $('.status').on('click', function()
        {
            //获取id
            var id = $(this).parent().parent().find('#ids').html();
            //获取对象
            var obj = $(this);
            $.ajax({
                type:'POST',
                url:"{{ url('admin/user/status') }}",
                data:{id:id},
                success:function(data)
                {
                    if(data == 2)
                    {
                        alert('修改失败');
                    }else if(data == 0)
                    {
                        obj.html('禁用');
                    }else if(data == 1)
                    {
                        obj.html('启用');
                    }
                },
                error:function()
                {
                    alert('异常');
                }
            });

        });
    }

    </script>

@endsection